<template>
	<view>
		<view class="wrap-container">
			<view class="" v-for="(item,index) in AlarmRealList" :key="index">
				<view class="warp-input">
					<view class="warp-text">{{item.structure_name}}</view>
				</view>
				<u-gap height="5" bg-color="#f5f5f5"></u-gap>
				<view class="warp-input">
					<view class="warp-text">报警类型</view>
					<view class="warp-text">{{item.alarm_type1}}</view>
				</view>
				<u-gap height="5" bg-color="#f5f5f5"></u-gap>
				<view class="warp-input">
					<view class="warp-text">报警优先级</view>
					<view class="warp-text">{{item.alarm_priority}}</view>
				</view>
				<u-gap height="5" bg-color="#f5f5f5"></u-gap>
				<view class="warp-input">
					<view class="warp-text">报警值</view>
					<view class="warp-text">{{item.alarm_value}}</view>
				</view>
				<u-gap height="5" bg-color="#f5f5f5"></u-gap>
				<view class="warp-input">
					<view class="warp-text">报警时间</view>
					<view class="warp-text">{{item.alarm_time}}</view>
				</view>
				<u-gap height="5" bg-color="#f5f5f5"></u-gap>
				<view class="warp-input">
					<view class="warp-text" style="width: 30%;">报警描述</view>
					<view class="warp-text" style="width: 70%;">{{item.alarm_description}}</view>
				</view>
				<u-gap height="5" bg-color="#f5f5f5"></u-gap>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				priorityMap: {
					low: '初级',
					medium: '中级',
					high: '高级',
					highest: '紧急'
				},
				alarmTypeMap: {
					"limit": "限值报警",
					"switch": "开关报警",
					"difference": "偏差报警",
					"rate": "变化率报警",
					"discrepancy": "匹配报警",
					"pattern": "位模式报警",
					"quality": "质量戳报警",
					"combine": "计算报警",
					"recipe": "配方驱动报警",
					"controller": "控制器输出报警",
					"system": "系统诊断报警",
					"instrument": "设备诊断报警",
					"call": "人工呼叫报警",
					"adaptive": "自适应报警",
					"measurement": "超限测量报警",
					"array": "工况报警"
				},
				AlarmRealList: [{
					alarm_time: '',
					alarm_priority: '',
					alarm_content: "",
					alarm_duration: '',
					structure_name: "",
					alarm_value: "",
					alarm_description: "",
					alarm_type1: ""
				}],
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getDetails()
		},

		methods: {
			navDeclaration() {
				uni.navigateTo({
					url: '/pages/sys/eventwororder/adddeclaration/adddeclaration'
				});
			},
			getDetails() {
				this.$u.api.getFalarmDetails({
					algorithmProcessId: "getFalarmDetails",
					param: {
						data: {
							id: this.id
						}
					}
				}).then(res => {
					this.AlarmRealList = this.processAlarmData(res.data.data.result);
					console.log('AlarmRealList:', this.AlarmRealList);
				}).catch(error => {
					console.error('数据获取错误:', error.message || error);
					alert('数据刷新失败，请稍后再试。');
				});
			},

			processAlarmData(data) {
				return data.map(item => {
					if (item.alarm_priority in this.priorityMap) {
						item.alarm_priority = this.priorityMap[item.alarm_priority];
					}
					if (item.alarm_type1 in this.alarmTypeMap) {
						item.alarm_type1 = this.alarmTypeMap[item.alarm_type1];
					}
					return item;
				});
			}

		},
	}
</script>

<style lang="scss">
	@import 'style/detailFalarm.scss';
</style>